package com.xr.common.enums;

import com.xr.common.utils.EnumUtil;

import java.util.Optional;

/**
 * description:用户性别枚举
 * @author: wls
 * @date: 2023/8/29 11:37
 * @version:1.0
 */
public enum UserSex {
    MAN(1, "男"), WOMAN(0, "女"), UNKNOWN(3, "保密");

    private final int code;
    private final String info;

    UserSex(int code, String info)
    {
        this.code = code;
        this.info = info;
    }

    public int getCode()
    {
        return code;
    }

    public String getInfo()
    {
        return info;
    }

    public static String getInfoByCode(Integer code){
        Optional<UserSex> m1 = EnumUtil.getEnumObject(UserSex.class, e -> e.getCode() == code);
        return m1.isPresent() ? m1.get().getInfo() : null;
    }

    public static Integer getCodeByInfo(String info){
        Optional<UserSex> m1 = EnumUtil.getEnumObject(UserSex.class, e -> e.getInfo().equals(info));
        return m1.isPresent() ? m1.get().getCode() : null;
    }
}
